package Cam2zyx0711;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;

public class DrawMouse implements ActionListener {
    private Graphics g;

    public DrawMouse(Graphics g) {
        this.g = g;
    }

    public void actionPerformed(ActionEvent e) {
        //System.out.println(".....");
        int[][]data= image("D:\\JAVAproject\\idea\\BeautyCam\\src\\Cam2zyx0711\\zyx.jpg");//图片放在项目目录下
        for (int i = 0; i <data.length; i++) {
            for (int j = 0; j < data[i].length; j++) {
                //得到颜色值，画出每一个点
                Color c=new Color(data[i][j]);
                g.setColor(c);//g.setColor(new Color(data[i][j])）；
                g.fillOval(i/2+50, j/2+50, 2, 2);
            }
        }
    }
    private int[][] image(String imageName) {
        File file = new File(imageName);
        BufferedImage bi = null;
        try {
            bi = ImageIO.read(file); //从文件到图片对象
        } catch (Exception e) { e.printStackTrace();
        }
        int w = bi.getWidth(); //图片的宽
        int h = bi.getHeight(); //图片的高
        int[][] imIndex=new int[w][h];//存像素值的二维数组
        //System.out.println("w=" + w + " h=" + h );
        for (int i = 0; i < w; i++) {
            for (int j = 0; j < h; j++) {
                imIndex[i][j] = bi.getRGB(i, j); //i,j 位置的 Color 值，每个像素点的 color 存入数组
            }
        }
        return imIndex;
    }


}

